#!/bin/bash
#
#  Fetch the Win32 wheels from Appveyor
#
if [ $# -lt 1 ]; then
    echo "usage: fetch-win32-wheels <netifaces-version> [tag]"
    exit 1;
fi

if [ $# -ge 2 ]; then
    maybetag="tag=$2&"
else
    maybetag=
fi

niversion=$1
artifact_url="https://ci.appveyor.com/api/projects/al45tair/netifaces/artifacts"
win32_versions="27 34 35 36 37 38"
amd64_versions="27 36 37 38"

for version in $win32_versions; do
    maybe_m=
    if [ $version -lt 38 ]; then
	maybe_m=m
    fi
    wheel=netifaces-$niversion-cp$version-cp${version}${maybe_m}-win32.whl
    url="$artifact_url/dist/$wheel?${maybetag}job=Environment:%20PYTHON=C:\\Python$version"
    echo -n "$wheel..."
    if curl -s -L -o wheelhouse/$wheel $url; then
	echo "ok"
    else
	echo "failed"
	exit 1
    fi
done

for version in $amd64_versions; do
    maybe_m=
    if [ $version -lt 38 ]; then
	maybe_m=m
    fi
    wheel=netifaces-$niversion-cp$version-cp${version}${maybe_m}-win_amd64.whl
    url="$artifact_url/dist/$wheel?${maybetag}job=Environment:%20PYTHON=C:\\Python$version-x64"
    echo -n "$wheel..."
    if curl -s -L -o wheelhouse/$wheel $url; then
	echo "ok"
    else
	echo "failed"
	exit 1
    fi
done
